package cn.micai.base.io;

import java.io.*;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/20 15:23
 */
public class LineNumberReaderExample {

    public static void main(String [] args) {

        try {
            File file = new File("D://newFile.txt");

            if (file.exists()) {
                FileReader fileReader = new FileReader(file);
                LineNumberReader lineNumberReader = new LineNumberReader(fileReader);
                int linenumber = 0;
                while (lineNumberReader.readLine() != null) {
                    linenumber ++;
                }
                System.out.println("Total number of lines : " + linenumber);
                lineNumberReader.close();
                fileReader.close();
            } else {
                System.out.println("File does not exists!");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
